using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Globalization;
using System.Security.Cryptography;
using Accountability4net;

namespace Accountability4net.FileMonengineProvider
{
    public class FileAccount: BaseAccount
    {
        object mutex_ = new object();
        FileMonengineProvider provider_;
        protected FileAccount()
            : base()
        {
        }

        public FileAccount(FileMonengineProvider provider)
            :this()
        {
            provider_ = provider;
        }

        public static IAccount Parse(XmlNode node)
        {
            return Parse(node, null);
        }

        public static IAccount Parse(XmlNode node, FileMonengineProvider provider)
        {
            FileAccount account = new FileAccount(provider);
            account.Number = Int32.Parse(node.Attributes["number"].Value);
            account.Type = (AccountType)Enum.Parse(typeof(AccountType), node.Attributes["type"].Value);
            account.Name = node.Attributes["name"].Value;
            account.Description = node.Attributes["description"].Value;
            return account;
        }

        public XmlNode Write(XmlNode element)
        {
            XmlNode node = element.OwnerDocument.CreateElement("account", element.NamespaceURI);
            element.AppendChild(node);
            XmlUtility.CreateAttribute(node, "number", Number);
            XmlUtility.CreateAttribute(node, "type", Type);
            XmlUtility.CreateAttribute(node, "name", Name);
            XmlUtility.CreateAttribute(node, "description", Description);
            return node;
        }
    }
}
